/**
 * Created by Dalyn on 2017/5/4.
 */
import React from "react";
import Relay from 'react-relay';
import { hashHistory } from 'react-router';
import { Table,Icon,message } from 'antd';
import Pagination from "../Pagination"
import ProductionProcessMutation from './mutation/ProductionProcessMutation';
import "./css/productionManagement_process.css";
import "./css/productionManagement_common.css";

export default class ProductionProcess extends React.Component {
    constructor(){
        super();
        this.state={
            enId: sessionStorage.getItem('enterpriseId'),
            totalResult : '',          //分页总条数
            pageSize : '10',      //每页显示条数
            pageNum : '1',
            processData: [],
            searchInput: '',
            loading: true,
        }
        this.uid = sessionStorage.getItem('uid')
        this.enterpriseId = sessionStorage.getItem('enterpriseId')
    }

    componentWillMount() {
        // console.dir(this.props.orderId);
      this.getProductProcess()
    }

    getProductProcess() {
      Relay.Store.commitUpdate(
          new ProductionProcessMutation({
              enId: this.props.partb,
              status: '3, 4', //已签订
              orderType: 1,  // 成衣 1
              pageSize: this.state.pageSize,
              pageNum: this.state.pageNum,
              partbName: this.state.searchInput,
              orderId:this.props.orderId
          }),
          {
              onFailure: () => {
                  console.log("请求失败")
                  this.setState({
                    loading: false
                  })
              },
              onSuccess: (response) => {
                let errorCode = response.getproductProcess.getproductProcess.errorCode
                if(errorCode == 0) {
                  let processData = response.getproductProcess.getproductProcess.processRecords
                  let totalResult = response.getproductProcess.getproductProcess.totalResult
                  if (processData) {
                    this.setState({
                      processData: processData,
                      totalResult:totalResult,
                      loading: false
                    })
                  }
                }
              }
          }
      );
    }

    _SearchByClient(){
        this.setState({
            pageNum: 1
        },()=>{
            this.getProductProcess()
        })
    }
    searchChange(e) {
      this.setState({
        searchInput: e.target.value
      })
    }

    onfocusInput(){

    }

    bluronInput(){

    }

    updateProcessClick(record) {
      hashHistory.push({
        pathname:'/ProductionProcessDetail/',
        state:{'partBname': record.partBname,'gid':record.gid,'orderId':record.orderId,'quality':record.quality,'styleNo':record.styleNo}
      })
    }

    /*页码*/
    onSure(size, num) {
        this.setState({
            pageSize: size,
            pageNum: num,
            loading:true,
        }, this.getProductProcess)
    }

    render() {
      let dataLength = this.state.processData.length
      const columns = [
        {
          title: '序号',
          dataIndex: 'index',
          key: 'index',
          width: 80,
          render: ((text, record, index) => {
            return ++index;
          })
        },
        // {
        //   title: '订单编号',
        //   dataIndex: 'orderId',
        //   key: 'orderId',
        //   width: 200,
        //   render: ((text, record, index) => {
        //     this.state.processData[index].opa0 = 1
        //     if (index > 0 && index < dataLength && (this.state.processData[index].orderId == this.state.processData[index-1].orderId)) {
        //       if(index+1 != dataLength) {
        //         this.state.processData[index+1].opa0 = 0
        //       }
        //       if (record.opa0 == 0) {
        //         <span style={{opactity: '0'}}>{record.orderId}</span>
        //       }
        //     } else {
        //       return record.orderId
        //     }
        //   })
        // },
        // {
        //   title: '客户',
        //   dataIndex: 'partBname',
        //   key: 'partBname',
        //   width: 231,
        // },
        {
          title: '款号',
          dataIndex: 'styleNo',
          key: 'styleNo',
          width: 118,
        }, {
          title: '数量',
          dataIndex: 'quality',
          key: 'quality',
          width: 80,
        },{
          title: '裁剪数',
          dataIndex: 'cutQua',
          key: 'cutQua',
          width: 80,
        },{
          title: '裁剪欠数',
          dataIndex: 'cutQuaRemain',
          key: 'cutQuaRemain',
          width: 80,
          className: 'redColor'
        },{
          title: '缝制数',
          dataIndex: 'sewQua',
          key: 'sewQua',
          width: 80,
        },{
          title: '缝制欠数',
          dataIndex: 'sewQuaRemain',
          key: 'sewQuaRemain',
          width: 80,
          className: 'redColor'
        },{
          title: '后整数',
          dataIndex: 'afterQua',
          key: 'afterQua',
          width: 80,
        },{
          title: '后整欠数',
          dataIndex: 'afterQuaRemain',
          key: 'afterQuaRemain',
          width: 80,
          className: 'redColor'
        },{
          title: '包装数',
          dataIndex: 'packQua',
          key: 'packQua',
          width: 80,
        },{
          title: '包装欠数',
          dataIndex: 'packQuaRemain',
          key: 'packQuaRemain',
          width: 80,
          className: 'redColor'
        }
      ];
        return (
          <div className="order_production_manage_process_box">
            <Table
              columns={columns}
              dataSource={this.state.processData}
              pagination={false}
              // bordered
              rowKey={record => record.gid}
              loading={this.state.loading}
              className="order_table"
            />
            <br/>
            <Pagination eachSize={this.state.pageSize} dataSize={this.state.totalResult}
                        onSure={this.onSure.bind(this)} ref={'pagination'}/>
          </div>
        )
    }
}
